package com.java110.mall.cart.cmd.storeOrder;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.storeOrder.ResultComputeStoreOrderPriceDto;
import com.java110.intf.cart.IUnifiedOrderInnerServiceSMO;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 计算秒杀价格
 */
@Java110Cmd(serviceCode = "storeOrder.computeSkillProductPrice")
public class ComputeSkillProductPriceCmd extends Cmd {

    @Autowired
    private IUnifiedOrderInnerServiceSMO unifiedOrderInnerServiceSMOImpl;
    /**
     * shopId: that.shopId,
     * cartType: param.CART_TYPE.SHOP,
     * productId: this.productId,
     * valueId: this.valueId,
     * goodsNum: this.goodsNum,
     * killId: this.killId
     * @param event              事件对象
     * @param context 请求报文数据
     * @param reqJson
     * @throws CmdException
     */
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {

        Assert.hasKeyAndValue(reqJson,"shopId","未包含商铺");
        Assert.hasKeyAndValue(reqJson,"productId","未包含productId");
        Assert.hasKeyAndValue(reqJson,"valueId","未包含valueId");
        Assert.hasKeyAndValue(reqJson,"goodsNum","未包含goodsNum");
        Assert.hasKeyAndValue(reqJson,"killId","未包含killId");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        ResultComputeStoreOrderPriceDto resultComputeStoreOrderPriceDto = unifiedOrderInnerServiceSMOImpl.computeSkillProductPrice(reqJson);
        context.setResponseEntity(ResultVo.createResponseEntity(resultComputeStoreOrderPriceDto));
    }
}
